//
//  MarryView.m
//  DaaaQing
//
//  Created by iOSer on 2020/8/7.
//  Copyright © 2020 Fireloli. All rights reserved.
//

#import "MarryView.h"
@interface MarryView()

@property (nonatomic, strong) UIButton * errorLabel;
@property (nonatomic, strong) UIButton * noBtn;
@end

@implementation MarryView

- (instancetype)init
{
    if (self = [super init]) {
        
        self.contentSize = CGSizeMake(kScreenWidth, kScreenHeight);
        self.animatedType = GSPopAnimatedPlain;
        self.superBgColor = [UIColor skyBlue];
        [self settingUI];
    }
    
    return self;
}

-(void)settingUI{
    UIImageView * imgView = [[UIImageView alloc] init];
    imgView.image = [UIImage imageNamed:@"marry.png"];
    [self addSubview:imgView];
    
    UILabel * label = [UILabel new];
    label.textColor = [UIColor orangeRed];
    label.text = @"你愿意嫁给我吗，结发为夫妻，恩爱两不疑";
    label.font = [UIFont fontWithName:kXingKaiFontName size:24];
    label.numberOfLines = 0;
    label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label];
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"我愿意" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont fontWithName:kXingKaiFontName size:18];
    btn.backgroundColor = [UIColor redColor];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(yesAction) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.masksToBounds = YES;
    btn.layer.cornerRadius = 6;
    
    UIButton * btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setTitle:@"考虑考虑" forState:UIControlStateNormal];
    btn1.titleLabel.font = [UIFont fontWithName:kXingKaiFontName size:18];
    btn1.backgroundColor = [UIColor grayColor];
    [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(noAction) forControlEvents:UIControlEventTouchUpInside];
    btn1.layer.masksToBounds = YES;
    btn1.layer.cornerRadius = 6;
    
    [self addSubview:btn];
    
    [self addSubview:btn1];
    
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(kScreenWidth/640.0*541);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.right.lessThanOrEqualTo(self).offset(-20);
        make.top.equalTo(imgView.mas_bottom).offset(40);
    }];
    
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(120, 44));
        make.top.equalTo(label.mas_bottom).offset(40);
    }];
    
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(120, 44));
        make.top.equalTo(btn.mas_bottom).offset(40);
    }];
    
    self.noBtn = btn1;
    
    [self addSubview:self.errorLabel];
    [self.errorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(260, 60));
    }];
    
}

-(void)yesAction{
    [self hideAnimated];
}

-(void)noAction{
    [self.noBtn removeFromSuperview];
    self.errorLabel.hidden = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.errorLabel.hidden = YES;
    });
}

- (UIButton *)errorLabel{
    if (!_errorLabel) {
        _errorLabel = [UIButton buttonWithType:UIButtonTypeCustom];
        [_errorLabel setTitle:@"恭喜已排除错误答案" forState:UIControlStateNormal];
        [_errorLabel.titleLabel setFont:[UIFont fontWithName:kXingKaiFontName size:16]];
        [_errorLabel setTitleColor:[UIColor orangeRed] forState:UIControlStateNormal];
        _errorLabel.titleEdgeInsets = UIEdgeInsetsMake(8, 16, 8, 16);
        _errorLabel.layer.masksToBounds = YES;
        _errorLabel.layer.cornerRadius = 6;
        _errorLabel.hidden = YES;
        _errorLabel.userInteractionEnabled = NO;
        _errorLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.85];
    }
    return _errorLabel;
}

@end
